package logic

import (
	"context"
	"gorm.io/gorm"
	"user_srv/internal/svc"
	"user_srv/models/mysql"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type PositionUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPositionUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PositionUpdateLogic {
	return &PositionUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 职位修改
func (l *PositionUpdateLogic) PositionUpdate(in *user.PositionUpdateRequest) (*user.PositionUpdateResponse, error) {
	// todo: add your logic here and delete this line

	position := mysql.Position{
		Model:         gorm.Model{ID: uint(in.Id)},
		Price:         float64(in.Price),
		Qualification: in.Qualification,
	}

	mysql.DB.Debug().Where("id = ?", in.Id).Updates(&position)

	return &user.PositionUpdateResponse{
		Id: int64(position.ID),
	}, nil
}
